//
// Created by LiuYou on 2021/10/24.
//

#include <iostream>
#include <unistd.h>
#include "AnyTimer.hpp"


/**
 * @brief
 * @example     func1((void*) "GO" );
 * @param ptr
 */
static void func1(void* ptr) {
    printf( __FUNCTION__ );
    printf( "(): %s\n", (const char*) ptr );
}

static void func2(void* ptr) {
    printf( __FUNCTION__ );
    printf( "(): %s\n", (const char*) ptr );
}

int main(int argc, char** argv) {
    /*
     * 希望5秒钟后调用 func1();
     * 希望2钟之后调用 func2();
     * 希望7秒钟之后调用 func1();
     */

    puts( "Begin" );

//    func1((void*) "aaa" );
//    func2((void*) "bbb" );
//    func1((void*) "ccc" );

    int job1 = addJob( 5, func1, (void*) "aaa" );
    if (job1 < 0) {
        fprintf( stderr, "addJob();出错了。\n" );
        exit( 1 );
    }
    int job2 = addJob( 2, func2, (void*) "bbb" );
    if (job2 < 0) {
        fprintf( stderr, "addJob();出错了。\n" );
        exit( 1 );
    }
    int job3 = addJob( 7, func1, (void*) "ccc" );
    if (job3 < 0) {
        fprintf( stderr, "addJob();出错了。\n" );
        exit( 1 );
    }


    puts( "end" );


    while (true) {
        write( STDOUT_FILENO, ".", 1 );
        sleep( 1 );
    }


    return 0;
}
